package co.com.javeriana.aes.patrones.aprovisionamiento.server;

import co.com.javeriana.aes.patrones.aprovisionamiento.cliente.Cliente;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    private static int port = 5555, maxConnections = 0;

    // Listen for incoming connections and handle them
    public static void main(String[] args) {
        int i = 0;

        try {
            ServerSocket listener = new ServerSocket(port);
            Socket server;

            while ((i++ < maxConnections) || (maxConnections == 0)) {

                server = listener.accept();
                Cliente cliente = new Cliente(server);
                Thread t = new Thread(cliente);
                t.start();
            }
        } catch (IOException ioe) {
            System.out.println("IOException on socket listen: " + ioe);
            ioe.printStackTrace();
        }
    }
}
